#include "metadata.h"
#include <cstring>
#include <string>
#include <iostream>
#include "../security_msg.pb.h"

using namespace std;

Metadata::Metadata(const char *data_header, int data_header_size, const char *data, int data_size)
{
    header_buf_len_ = data_header_size;
    header_buf_ = new char[header_buf_len_];
    memcpy(header_buf_, data_header, data_header_size);
    if (data_size > 0)
    {
        msg_buf_len_ = data_size;
        msg_buf_ = new char[msg_buf_len_];
        memcpy(msg_buf_, data, data_size);
    }
}

Metadata::~Metadata()
{
    if (header_buf_)
    {
        delete[] header_buf_;
        header_buf_ = nullptr;
    }
    if (msg_buf_)
    {
        delete[] msg_buf_;
        msg_buf_ = nullptr;
    }
}

void Metadata::set_ttl(int ttl)
{
    this->ttl_ = ttl;
}

int Metadata::get_ttl()
{
    return this->ttl_;
}

void Metadata::Decrement()
{
    this->ttl_--;
}

char *Metadata::GetDataHeader() const
{
    return this->header_buf_;
}

int Metadata::GetDataHeaderSize() const
{
    return this->header_buf_len_;
}

char *Metadata::GetData() const
{
    return this->msg_buf_;
}

int Metadata::GetDataSize() const
{
    return this->msg_buf_len_;
}